package com.ruirui.demo.strategy.context;

import com.ruirui.demo.strategy.GradingStrategy;
import com.ruirui.demo.strategy.entity.Answer;
import com.ruirui.demo.strategy.entity.Question;
import com.ruirui.demo.strategy.impl.EssayStrategy;
import com.ruirui.demo.strategy.impl.SingleChoiceStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class GradingFactory {
    @Autowired
    private  EssayStrategy  essayStrategy;
    @Autowired
    private  SingleChoiceStrategy singleChoiceStrategy;



//    public void setStrategy(GradingStrategy strategy) {
//        this.strategy = strategy;
//    }

    /**
     * 多态传入类型
     * @param question
     * @return
     */
    public GradingStrategy getStrategy(Question question) {
        return switch (question.getType()) {
            case SINGLE_CHOICE -> singleChoiceStrategy;
            case ESSAY -> essayStrategy;
            default -> throw new RuntimeException("题目不存在");
        };
    }
//    public int execute(Question question, Answer answer) {
//        return strategy.grade(question, answer);
//    }
}
